<template>
    <div class="mod-admin__education">
        <div class="content">
            <div class="content-btns">
                <el-button v-if="state.hasPermission('sys:user:save')" type="primary" @click="addOrUpdateHandle()">{{
                    $t("add") }}</el-button>
            </div>
            <el-table v-loading="state.dataListLoading" :data="state.dataList" row-key="id"
                :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
                @sort-change="state.dataListSortChangeHandle" style="width: 100%;height: calc(100vh - 390px);">
                <el-table-column prop="name" :label="$t('dept.name')" sortable="custom" header-align="left"
                    align="left"></el-table-column>
                <el-table-column prop="parentName" :label="$t('dept.parentName')" sortable="custom" header-align="left"
                    align="left"></el-table-column>
                <el-table-column prop="type" :label="$t('dept.type')" sortable="custom" header-align="center"
                    align="center">
                    <template v-slot="scope">
                        {{ state.getDictLabel("dept_type", scope.row.type) }}
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="director" :label="$t('school.director')" sortable="custom" header-align="center"
                    align="center">
                </el-table-column> -->
                <!-- <el-table-column prop="directorMobile" :label="$t('school.directorMobile')" sortable="custom"
                    header-align="center" align="center">
                </el-table-column> -->

                <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
                    <template v-slot="scope">
                        <el-button v-if="state.hasPermission('sys:user:update')" type="primary" link
                            @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
                        <el-button v-if="state.hasPermission('sys:user:delete')" type="primary" link
                            @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
    </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs, computed } from "vue";
import AddOrUpdate from "./class-add-or-update.vue";

const view = reactive({
    getDataListURL: "/data/class/list",
    deleteURL: "/data/class/delete",
    deleteIsPost: false,
    dataForm: {
        name: "",
    }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
    addOrUpdateRef.value.init(id);
};

</script>
<style lang="less" scoped>
.top-search {
    background-color: #fff;
    padding: 20px 30px 10px;
    border-radius: 10px;
    display: flex;

    /deep/ .el-form {
        width: 100%;
    }

    &_form {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;

        &_btn {
            display: flex;
        }
    }
}

.content {
    background-color: #fff;
    padding: 20px;
    border-radius: 10px;
    margin: 15px 0 0;

    .school-name {
        font-size: 18px;
        font-weight: bold;
        padding: 10px 0;
    }

    &-btns {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        margin-bottom: 20px;
    }
}
</style>